package com.gqj.meter.controller;

import com.gqj.common.annotation.Log;
import com.gqj.common.core.controller.BaseController;
import com.gqj.common.core.domain.AjaxResult;
import com.gqj.common.core.page.TableDataInfo;
import com.gqj.common.enums.BusinessType;
import com.gqj.common.utils.poi.ExcelUtil;
import com.gqj.meter.domain.SysDataBackupRecord;
import com.gqj.meter.service.ISysDataBackupRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 数据备份记录Controller
 *
 * @author lxq
 * @date lxq-01-09
 */
@Api(value = "/meter/dataBackupRecord", description = "数据备份记录")
@RestController
@RequestMapping("/meter/dataBackupRecord")
public class SysDataBackupRecordController extends BaseController
{
    @Autowired
    private ISysDataBackupRecordService sysDataBackupRecordService;

    /**
     * 查询数据备份记录列表
     */
    @ApiOperation("查询数据备份记录列表")
    @PreAuthorize("@ss.hasPermi('storage:dataBackupRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDataBackupRecord sysDataBackupRecord)
    {
        startPage();
        List<SysDataBackupRecord> list = sysDataBackupRecordService.selectSysDataBackupRecordList(sysDataBackupRecord);
        return getDataTable(list);
    }

    /**
     * 导出数据备份记录列表
     */
    @PreAuthorize("@ss.hasPermi('storage:dataBackupRecord:export')")
    @Log(title = "数据备份记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDataBackupRecord sysDataBackupRecord)
    {
        List<SysDataBackupRecord> list = sysDataBackupRecordService.selectSysDataBackupRecordList(sysDataBackupRecord);
        ExcelUtil<SysDataBackupRecord> util = new ExcelUtil<SysDataBackupRecord>(SysDataBackupRecord.class);
        util.exportExcel(response, list, "数据备份记录数据");
    }

    /**
     * 获取数据备份记录详细信息
     */
    @ApiOperation("获取数据备份记录详细信息")
    @PreAuthorize("@ss.hasPermi('storage:dataBackupRecord:query')")
    @GetMapping(value = "/{backupId}")
    public AjaxResult getInfo(@PathVariable("backupId") Long backupId)
    {
        return success(sysDataBackupRecordService.selectSysDataBackupRecordByBackupId(backupId));
    }

    /**
     * 新增数据备份记录
     */
    @ApiOperation("新增数据备份记录")
    @PreAuthorize("@ss.hasPermi('storage:dataBackupRecord:add')")
    @Log(title = "数据备份记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDataBackupRecord sysDataBackupRecord)
    {
        return toAjax(sysDataBackupRecordService.insertSysDataBackupRecord(sysDataBackupRecord));
    }

    /**
     * 修改数据备份记录
     */
    @ApiOperation("修改数据备份记录")
    @PreAuthorize("@ss.hasPermi('storage:dataBackupRecord:edit')")
    @Log(title = "数据备份记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDataBackupRecord sysDataBackupRecord)
    {
        return toAjax(sysDataBackupRecordService.updateSysDataBackupRecord(sysDataBackupRecord));
    }

    /**
     * 删除数据备份记录
     */
    @ApiOperation("删除数据备份记录")
    @PreAuthorize("@ss.hasPermi('storage:dataBackupRecord:remove')")
    @Log(title = "数据备份记录", businessType = BusinessType.DELETE)
	@GetMapping("/{backupIds}")
    public AjaxResult remove(@PathVariable Long[] backupIds)
    {
        return toAjax(sysDataBackupRecordService.deleteSysDataBackupRecordByBackupIds(backupIds));
    }

    /**
     * 生成数据备份记录
     */
    @ApiOperation("生成数据备份记录")
    @PreAuthorize("@ss.hasPermi('storage:dataBackupRecord:generateRecord')")
    @Log(title = "生成数据备份记录", businessType = BusinessType.DELETE)
    @GetMapping("/generateRecord")
    public AjaxResult generateRecord()
    {
        return toAjax(sysDataBackupRecordService.generateRecord());
    }
}
